const mongoose = require("mongoose");

const UserSchema = mongoose.Schema(
  {
    username: {
      type: String,
      trim: true,
      lowercase: true,
      required: true,
    },
    password: {
      type: String,
      trim: true,
      required: true,
      validate: {
        validator(value) {
          return value.length >= 3; // true校验通过
        },
      },
    },
    age: {
      type: Number,
      default: 30,
      min: 0,
      max: 120,
    },
    gender: {
      type: Number,
      enum: [0, 1],
    },
  },
  {
    timestamps: true,
  }
);
const UserModel = mongoose.model("User", UserSchema, "user");
module.exports = UserModel;
